﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Com.DA;
using Com.BU;

namespace ThermalEquipmentDesign.Model.Condenser.SprinklerR717
{
    public class SprinklerR717 : ObservableObject
    {
        // Declare fields for inputting
        #region Feild Input
        private double dbcoldProductivity;
        private double dbwaterTemperature;
        private double dbtemperature;
        private double dbhumidity;
        private double dbenthalpy;
        private double dbaverageEnthalpy;
        private double dbhumidityContent;
        private double dbaverageHumidityContent;
        private double dbinterDiameter = 0.057;
        private double dbexterDiameter = 0.05;
        private double dbdegreeIncreaseTemp;
        private double dblimitTemp;
        private double dblogaritDiffTemp;
        private double dbprandtlCoefficient;
        private double dbwaterExpenditure;
        private double dbwaterThermalCapacity;
        private double dbheatTransferCoefficient;
        private double dbdynamicViscosity;
        private double dbkinematicViscosity;
        private double dbdensity;
        private double dbthermalResistance;
        private double dbcalorificCoefficient;
        private double dbaverageAirThermalCapacity;
        private double dbevaporationCoefficient;
        private double dbaverageWaterThermalCapacity;
        private double dbdiffTemp;
        #endregion

        // Create properties for fields
        #region Properties Input
        public double dbColdProductivity
        {
            get { return dbcoldProductivity; }
            set { dbcoldProductivity = value; }
        }

        public double dbWaterTemperature
        {
            get { return dbwaterTemperature; }
            set { dbwaterTemperature = value; }
        }

        public double dbTemperature
        {
            get { return dbtemperature; }
            set { dbtemperature = value; }
        }

        public double dbHumidity
        {
            get { return dbhumidity; }
            set { dbhumidity = value; }
        }

        public double dbEnthalpy
        {
            get { return dbenthalpy; }
            set { dbenthalpy = value; }
        }

        public double dbAverageEnthalpy
        {
            get { return dbaverageEnthalpy; }
            set { dbaverageEnthalpy = value; }
        }

        public double dbHumidityContent
        {
            get { return dbhumidityContent; }
            set { dbhumidityContent = value; }
        }

        public double dbAverageHumidityContent
        {
            get { return dbaverageHumidityContent; }
            set { dbaverageHumidityContent = value; }
        }

        public double dbInterDiameter
        {
            get { return dbinterDiameter; }
            set { dbinterDiameter = value; }
        }

        public double dbExterDiameter
        {
            get { return dbexterDiameter; }
            set { dbexterDiameter = value; }
        }

        public double dbDegreeIncreaseTemp
        {
            get { return dbdegreeIncreaseTemp; }
            set { dbdegreeIncreaseTemp = value; }
        }

        public double dbLimitTemp
        {
            get { return dblimitTemp; }
            set
            {
                if (value != dblimitTemp)
                {
                    dblimitTemp = value;
                    SetAverageTemp();
                    OnPropertyChanged("dbLimitTemp");
                }
            }
        }

        public double dbLogaritDiffTemp
        {
            get { return dblogaritDiffTemp; }
            set { dblogaritDiffTemp = value; }
        }

        public double dbPrandtlCoefficient
        {
            get { return dbprandtlCoefficient; }
            set { dbprandtlCoefficient = value; }
        }

        public double dbWaterExpenditure
        {
            get { return dbwaterExpenditure; }
            set { dbwaterExpenditure = value; }
        }

        public double dbWaterThermalCapacity
        {
            get { return dbwaterThermalCapacity; }
            set { dbwaterThermalCapacity = value; }
        }

        public double dbHeatTransferCoefficient
        {
            get { return dbheatTransferCoefficient; }
            set { dbheatTransferCoefficient = value; }
        }

        public double dbDynamicViscosity
        {
            get { return dbdynamicViscosity; }
            set { dbdynamicViscosity = value; }
        }

        public double dbKinematicViscosity
        {
            get { return dbkinematicViscosity; }
            set { dbkinematicViscosity = value; }
        }

        public double dbDensity
        {
            get { return dbdensity; }
            set { dbdensity = value; }
        }

        public double dbThermalResistance
        {
            get { return dbthermalResistance; }
            set { dbthermalResistance = value; }
        }

        public double dbCalorificCoefficient
        {
            get { return dbcalorificCoefficient; }
            set { dbcalorificCoefficient = value; }
        }

        public double dbAverageAirThermalCapacity
        {
            get { return dbaverageAirThermalCapacity; }
            set { dbaverageAirThermalCapacity = value; }
        }

        public double dbEvaporationCoefficient
        {
            get { return dbevaporationCoefficient; }
            set { dbevaporationCoefficient = value; }
        }

        public double dbAverageWaterThermalCapacity
        {
            get { return dbaverageWaterThermalCapacity; }
            set { dbaverageWaterThermalCapacity = value; }
        }

        public double dbDiffTemp
        {
            get { return dbdiffTemp; }
            set { dbdiffTemp = value; }
        }
        #endregion

        /// <summary>
        /// Change value foe properties that realted with average temperature
        /// </summary>
        private void SetAverageTemp()
        {
            double dbaverageTemp = dblimitTemp + 5;
            tb_water_coefficients watercoefficients = LibraryManagerInCom.WaterCoefficientsList.SingleOrDefault(w => w.Temperature == dbaverageTemp);

            if (watercoefficients != null)
            {
                dbprandtlCoefficient = (double)watercoefficients.Prandtl_Coefficient;
                dbwaterThermalCapacity = (double)watercoefficients.HeatSpecific;
                dbheatTransferCoefficient = (double)watercoefficients.HeatConductivity;
                dbdynamicViscosity = (double)watercoefficients.DynamicViscosity;
                dbkinematicViscosity = (double)watercoefficients.KinematicViscosity;
                dbdensity = (double)watercoefficients.Density01;
                OnPropertyChanged("dbPrandtlCoefficient");
                OnPropertyChanged("dbWaterThermalCapacity");
                OnPropertyChanged("dbHeatTransferCoefficient");
                OnPropertyChanged("dbDynamicViscosity");
                OnPropertyChanged("dbKinematicViscosity");
                OnPropertyChanged("dbDensity");
            }
        }

    }
}
